

// 全局封装表单校验
export const rules = {
  imgURL: [ // 头像
    {
      required: true,
      message: '请上传头像',
      trigger: 'change',
    },
  ],
  name: [  // 昵称
    { required: true, message: '请输入你的昵称', trigger: 'blur' },
    { min: 2, max: 10, message: '长度在2-10位之间', trigger: 'blur' },
  ],
  label: [ // 类型
    {
      required: true,
      message: '请选择类型',
      trigger: 'change',
    },
  ],
  experience: [ // 工作经验
    { required: true, message: '请选择你的工作经验', trigger: 'blur' },
  ],
  TechnologyStack: [ // 技术栈
    { required: true, message: '请选择你的技术栈', trigger: 'blur' },
  ],
  Direction: [ // 职业方向
    {
      required: true,
      message: '请选择职业',
      trigger: 'change',
    },
  ],
  mobilePhone: [  // 手机号
  { required: true, message: '请填写你的手机号', trigger: 'blur' },
  { required: true, trigger: ["blur"], pattern: /^1[3456789]{1}\d{9}$/, message: '请输入正确的手机号' }
],
username: [  // 手机号
{ required: true, message: '请填写你的账号', trigger: 'blur' },
{ min: 2, max: 11, message: '长度在2-11位之间', trigger: 'blur' },
],
  wechat: [  // 微信
    { required: true, message: '请选择你的微信号', trigger: 'blur' },
    { min: 4, max: 10, message: '长度为4-10位', trigger: 'blur' },
  ],
  education: [ // 学历
    {
      required: true,
      message: '请选择你的学历',
      trigger: 'change',
    },
  ],
  agreement: [ // 协议
    {
      required: true,
      message: '请查阅协议',
      trigger: 'change',
    },
  ],
  City: [ // 城市
    {
      required: true,
      message: '请选择你的城市',
      trigger: 'change',
    },
  ],
  ZoneName: [ // 专区
    {
      required: true,
      message: '请选择你的专区',
      trigger: 'change',
    },
  ],
  classification: [ // 分类
    {
      required: true,
      message: '请选择你的分类',
      trigger: 'change',
    },
  ],
  school: [ //标题
    { required: true, message: '请你输入你的学校', trigger: 'blur' },
    { min: 5, max: 20, message: '长度为5-20位', trigger: 'blur' },
  ],
  Personal: [ //正文
    { required: true, message: '请你输入你的个性签名', trigger: 'blur' },
    { min: 2, max: 15, message: '长度为2-15位', trigger: 'blur' },
  ],
  PassWord: [ // 密码
    { required: true, message: '请你输入你的密码', trigger: 'blur' },
    { required: true, trigger: ["blur"], pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/, message: '至少8-16个字符,至少有一个大写字母和小写字母和1个数字' }
  ],
  money: [ // 金额
    { required: true, message: '请输入你的金额', trigger: 'blur' },
  ],
}


// 全局封装图片上传校验
export const beforeAvatarUpload = (rawFile) => {
  if (rawFile.type !== 'image/jpeg') {
    ElMessage.error('请使用jpg格式的图片')
    return false
  } else if (rawFile.size / 1024 / 1024 > 2) {
    ElMessage.error('图片大小不能超过 2MB!')
    return false
  }
  return true
}

export const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
}
